package com.gitee.ykr.lightweight.rpc.common.entity;

import io.netty.util.internal.StringUtil;
import lombok.Data;

import java.util.Objects;

/**
 * 封装了集群的实例
 * @author YKR
 * @Describe
 * @date 2021/8/23
 */
@Data
public class AppEntity {

    //实例所处的集群名
    private String name;
    //实例的host
    private String host;
    //实例的port
    private int port;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof AppEntity)) return false;
        AppEntity that = (AppEntity) o;
        return getPort() == that.getPort() &&
                Objects.equals( getHost(), that.getHost() ) &&
                Objects.equals( getName(), that.getName() );
    }

    @Override
    public int hashCode() {

        return Objects.hash( getHost(), getPort(), getName() );
    }

    public boolean validate() {
        if (StringUtil.isNullOrEmpty( name ) || StringUtil.isNullOrEmpty( host ) || port < 0) {
            return false;
        }
        return true;
    }


    @Override
    public String toString() {
        return "AppEntity{" +
                "name='" + name + '\'' +
                ", host='" + host + '\'' +
                ", port=" + port +
                '}';
    }
}
